package dataSource

import (
	"github.com/gomodule/redigo/redis"
	goRedis "github.com/go-redis/redis/v7"
)

type RedisInit struct {

}

func (redisInit *RedisInit) NewRedisInit() redis.Conn{
	pool := &redis.Pool{
		MaxIdle : 10,
		MaxActive : 0,
		IdleTimeout : 100,
		Dial : func()(redis.Conn, error){
			return redis.Dial("tcp", "127.0.0.1:6379")
		},
	}
	poolConn := pool.Get()

	return poolConn
}

func (redisInit *RedisInit) NewGoRedisInit() *goRedis.Client{
	rdb := goRedis.NewClient(&goRedis.Options{
		Addr:     "localhost:6379",
		Password: "", // no password set
		DB:       0,  // use default DB
	})

	_, err = rdb.Ping().Result()
	if err != nil {
		return nil
	}
	return rdb
}
